var app = new Vue({
  el: '#app',
  data: function () {
    return {
      loading: false,
      openDialog: false,
      reportData: null
    };
  },
  methods: {
    qcSiteCheck: function () {
      var processId = $('#workingProcedureName').val();
      if (SysUtil.isEmpty(processId)) {
        layAlert('请选择工序');
        return;
      }

      var order = pageData.order;
      var self = this;
      this.loading = true;
      ajaxRequest('procedure/getProcessQCTableByProcessId', {
        orderId: order.orderId,
        processId: processId,
        type: 1
      }).then(function (res) {
        self.loading = false;
        res = res[0];
        var details = res.qcList;
        if (SysUtil.isEmpty(details) || details[0].content === '') {
          layAlert('该工序没有设置qc巡检内容');
          return;
        }
        self.toQcSiteCheck(processId, res);
      }).catch(function () {
        self.loading = false;
      });
    },

    toQcSiteCheck: function (processId, res) {
      var order = pageData.order;
      var reportData = {
        orderId: order.orderId,
        companyOrderId: order.companyOrderId,
        factoryId: order.factoryId,
        customerId: order.customerId,
        customerOrderId: order.customerOrderId,
        details: res.qcList,
        selfCheckTime: res.selfCheckTime,
        siteCheckTime: res.siteCheckTime
      };

      var processList = pageData.processList;
      var obj = _.find(processList, {
        id: processId
      });
      reportData.processData = {
        processId: processId,
        processName: obj.processName
      };
      this.reportData = reportData;
      this.openDialog = true;
    },

    checkSuccess: function () {
      this.openDialog = false;
    },

    dailogClosed: function () {
      this.reportData = null;
    }
  },
  components: {
    RoutingInspection: RoutingInspection
  }
});
